home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 11008 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.3 KB

  1. Path: in1.uu.net!interaccess!usenet
  2. From: brianmcg@interaccess.com (Brian V. McGroarty)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: operator % - compiler error
  5. Date: 21 Mar 1996 14:13:46 GMT
  6. Organization: Internet Squire
  7. Message-ID: <4iro6q$2e9@nntp.interaccess.com>
  8. References: <4ini8g$i1u@spanky.pls.ov.com>
  9. Reply-To: brianmcg@interaccess.com
  10. NNTP-Posting-Host: d222.nhe.interaccess.com
  11. X-Newsreader: Internet Squire 1.20
  12.  
  13. This is something I've wondered about.  Why isn't the mod operator defined
  14. for floating point math?  It can be implemented easily enough via something
  15. like:
  16.  
  17. #define MOD( base, op ) ( (base) - ( (base) / (op) ) * (op) )
  18.  
  19. ..so it does have validity, however the efficiency of using the remainder
  20. on FPUs returning the remainder along with the result of a divide is lost
  21. -- a spurious subtraction and multiplication are added. 
  22.  
  23.  
  24.  
  25. glenn@ov.com wrote:
  26. >In article 6ul@hatathli.csulb.edu, davidcho@csulb.edu (David Cho) writes:
  27. >>When I try to compile, I get an erro message for the following line:        
  28.  
  29.  
  30. >>x=663608941*y%pow(2,32)  /*I want remainder*/
  31.  
  32. >>But the error message says "illegal use of floating point".  What does 
  33. >>that mean?  Isn't % used a an operator to calcuate the remainder?
  34.  
  35. >You're missing the point.  % needs an integer argument, and pow()
  36. >returns a double.
  37.  
  38.  
  39.  
  40. ---
  41. Brian Valters McGroarty -- brianmcg@bix.com
  42. phone/fax (847) 439-7714
  43.  
  44.  
  45.  
  46.